
/**
 * 缓存数据
 * @type {{add(*, *): void, data: {}, get(*): *, clear(*): void, clearAll(): void}}
 */
const CACHE = {
    data: {},
    get(key) {
        return CACHE.data[key];
    },
    add(key, value) {
        CACHE.data[key] = value;
    },
    clear(key) {
        delete CACHE.data[key];
    },
    clearAll() {
        CACHE.data = {};
    }
};

/**
 * 正在加载请求的缓存
 * @type {{add(*, *): void, data: {}, get(*): *, remove(*): void}}
 */
const loadingCache = {
    data: {},
    get(key) {
        return loadingCache.data[key];
    },
    add(key, promise) {
        loadingCache.data[key] = promise;
    },
    remove(key) {
        delete loadingCache.data[key];
    }
};

export {
    CACHE,
    loadingCache
};
